@extends('layouts._app')
@section('content')
    <body class="iframe-h">
    <div class="wrap-container email-wrap clearfix">
        <ul class="layui-fixbar">
            <li class="layui-icon layui-fixbar-top" id="layui-fixbar-top" onclick="topFunction()"
                style="display:none;">
            </li>
        </ul>
        <div class="row">
            <div class="email-edge col-lg-2"
                 style="display: inline-grid;;height: -webkit-fill-available;overflow: auto;">
                <dl class="email-folder">
                    <dt>文件夹</dt>
                    <div class="wrapper">
                        <ul id="demo1" class="layui-box layui-tree"></ul>
                    </div>
                </dl>
            </div>
            <div class="col-lg-10">
                <div class="email-content" style="overflow:auto; width:100%;height: -webkit-fill-available;">
                    @include('layouts._flash')
                    <div class="email-content-title layui-form">
                        <span class="write-title" title="{{$request['name']}}">{{sub($request['name'])}} ({{$res['name']['count']}})</span>
                    </div>
                    <div class="email-tool-btn clearfix">
                        <div class="col-lg-6 email-tool-btn-left">
                            <a class="layui-btn layui-btn-small layui-btn-primary" id='email-refresh-btn'
                               href="{{route('system.broken.index')}}?name={{$request['name']}}" data-title='刷新'>
                                <i class="layui-icon">&#x1002;</i>
                            </a>
                            <button class="layui-btn layui-btn-small layui-btn-primary" id='del-btn'
                                    data-title='删除'>
                                <i class="layui-icon">&#xe640;</i>
                            </button>
                        </div>
                    </div>
                    <div class="layui-form email-list">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                                <th>路径</th>
                                <th>最后操作时间</th>
                                <th>大小</th>
                                <th>名称</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($res['pic'] as $value)
                                @if(explode('/',$request['name'])[0] == 'file')
                                    <tr>
                                        <td>
                                            <input type="checkbox" data-id="{{$value['name'].$value['title']}}"
                                                   name="del" lay-skin="primary">
                                        </td>

                                        <td title="{{$value['name']}}">{{sub($value['name'],30)}}</td>
                                        <td title="{{\Carbon\Carbon::createFromTimestamp($value['last'])->toDateTimeString()}}">
                                            {{sub(\Carbon\Carbon::createFromTimestamp($value['last'])->toDateTimeString(),30)}}</td>
                                        <td title="{{$value['size']}}">{{sub(maxsize($value['size']))}}</td>
                                        <td>
                                            <a href="javascript:;"
                                               title="{{$value['title']}}">{{sub($value['title'],20)}}</a>
                                        </td>
                                        <td>
                                            <a class="layui-btn layui-btn-mini layui-btn-danger del_btn" title="删除"
                                               onClick="return confirm('确定删除?');"
                                               href="{{route('system.broken.delete')}}?name={{$request['name']}}&static={{$request['static']}}&status=1&filter=true&title={{$value['name'].$value['title']}}">
                                                <i class="layui-icon">&#xe640;</i>
                                            </a>
                                        </td>
                                    </tr>
                                @endif
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('static/admin/layui/layui.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('static/admin/js/common.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/jquery.min.js')}}" type="text/javascript" charset="utf-8"></script>
    <script src="{{asset('js/common.js')}}"></script>

    <script>
        /**
         * 回到顶部 自动隐藏
         */
        function topFunction() {
            $(".email-content").animate({scrollTop: 0}, "slow");
            $('#layui-fixbar-top').attr('style', 'display:none;');
        }

        /**
         * 自动显示和隐藏 回到顶部图标
         */
        function scrollFun() {
            var layuiBodyScrollTop = document.getElementsByClassName('welcome-container')[0].scrollTop;
            if (layuiBodyScrollTop > 400) {
                document.getElementById("layui-fixbar-top").style.display = "block";
            } else {
                document.getElementById("layui-fixbar-top").style.display = "none";
            }
        }

        /*注册事件*/
        if (document.addEventListener) {
            document.addEventListener('DOMMouseScroll', scrollFun, false);
        }//W3C
        window.onmousewheel = document.onmousewheel = scrollFun;//IE/Opera/Chrome

        layui.use(['form', 'jquery', 'dialog', 'tree', 'element'], function () {
            var form = layui.form(),
                dialog = layui.dialog,
                tree = layui.tree,
                elem = layui.element,
                $ = layui.jquery;
            var topcateid = 0;

            treeCategory();

            //删除
            $('#del-btn').click(function () {
                var ids = [];
                $("input[name='del']:checked").each(function (i) {
                    ids[i] = $(this).data('id');
                });
                if (ids.length == 0) {
                    layer.msg('请选择要删除的', {icon: 5, time: 3000});
                    return false;
                }
                dialog.confirm({
                    message: '您确定要删除选中项',
                    success: function () {
                        $.ajax({
                            type: 'GET',
                            url: '{{route('system.broken.delete')}}',
                            data: {
                                title: ids,
                                name: "{{$request['name']}}",
                                static: "{{$request['static']}}",
                                status: 2,
                                filter: 'true'
                            },
                            dataType: "json",
                            beforeSend: function () {
                                layer.load(1, {
                                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                                });
                            },
                            complete: function (XHR) {
                                XHR = null;
                            },
                            error: function (xhr) {//获取ajax的错误信息
                                layer.alert(xhr.responseText, "Failed", function () {
                                    layer.closeAll();
                                });
                            },
                            success: function (res) {
                                layer.closeAll();
                                if (res.code == 403) {
                                    layer.msg(res.msg, {icon: 4, time: 3000})
                                    return false;
                                }
                                if (res.code != 200) {
                                    layer.msg(res.msg, {icon: 5, time: 3000})
                                    return false;
                                }
                                layer.msg(res.msg, {icon: 1, time: 3000}, function () {
                                    window.location.reload();
                                });
                            }
                        })
                    }
                });
            });

            function treeCategory(status) {
                $.ajax({
                    type: 'GET',
                    url: '{{route('system.broken.tree')}}',
                    data: {static: status, name: '{{$request['name']}}'},
                    dataType: "json",
                    beforeSend: function () {
                        layer.load(1, {
                            shade: [0.1, '#333333'] //0.1透明度的白色背景
                        });
                    },
                    complete: function (XHR) {
                        XHR = null;
                    },
                    error: function (xhr) {//获取ajax的错误信息
                        layer.alert(xhr.responseText, "Failed", function () {
                            layer.closeAll();
                        });
                    },
                    success: function (res) {
                        layer.closeAll();
                        if (res.code == 403) {
                            layer.msg(res.msg, {icon: 4, time: 3000})
                            return false;
                        }
                        if (res.code != 200) {
                            layer.msg(res.msg, {icon: 4, time: 3000})
                            return false;
                        }
                        tree({
                            elem: '#demo1', skin: 'shihuang', nodes: res.data, click: function (node) {
                                window.location.href = '{{route('system.broken.index')}}?static={{$request['static']}}&name=' + node['id']
                            }
                        });
                    }
                });
                $(document).on('click', '.title3', function () {
                    var id = $(this).parents('li').data('id');
                    dialog.confirm({
                        message: '您确定要删除当前文件夹及文件夹下所有文件',
                        success: function () {
                            $.ajax({
                                type: 'GET',
                                url: '{{route('system.broken.delete')}}',
                                data: {
                                    name: id,
                                    static: "{{$request['static']}}",
                                    status: 3
                                },
                                dataType: "json",
                                beforeSend: function () {
                                    layer.load(1, {
                                        shade: [0.1, '#333333'] //0.1透明度的白色背景
                                    });
                                },
                                complete: function (XHR) {
                                    XHR = null;
                                },
                                error: function (xhr) {//获取ajax的错误信息
                                    layer.alert(xhr.responseText, "Failed", function () {
                                        layer.closeAll();
                                    });
                                },
                                success: function (res) {
                                    layer.closeAll();
                                    if (res.code == 403) {
                                        layer.msg(res.msg, {icon: 4, time: 3000})
                                        return false;
                                    }
                                    if (res.code != 200) {
                                        layer.msg(res.msg, {icon: 5, time: 3000})
                                        return false;
                                    }
                                    layer.msg(res.msg, {icon: 1, time: 3000}, function () {
                                        window.location.reload();
                                    });
                                }
                            })
                        }
                    });
                })
            }

            form.render();

            //非手机端，设置高度
            if (window.innerWidth >= 768) {
                $('.email-content').css('height', window.innerHeight - 30);
            }
            $(window).resize(function () {
                $('.email-content').css('height', window.innerHeight - 30);
            })


        });
    </script>
    </body>
@endsection
